package com.wwb.w0503;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class MainActivity2 extends AppCompatActivity {

    ListView mListView;
     String[] titles={"胡胡胡","李四","王五"};
     String[] tels={"18336117544","13277778888","18877778888"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        mListView=(ListView) findViewById(R.id.lv);

        MyBaseAdapter mAdapter = new MyBaseAdapter();
        mListView.setAdapter(mAdapter);

        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long l) {
                Intent data=new Intent();
                data.putExtra("tel",tels[position]);
                System.out.println(tels[position]);
                setResult(2,data);
                finish();
            }
        });


    }

    class MyBaseAdapter extends BaseAdapter{

        @Override
        public int getCount() {

            return titles.length;
        }

        @Override
        public Object getItem(int i) {

            return titles[i];
        }

        @Override
        public long getItemId(int i) {
            return i;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            View view1=View.inflate(MainActivity2.this,R.layout.list_item,null);
            TextView title=view1.findViewById(R.id.title);
            TextView tel= view1.findViewById(R.id.tel);

            title.setText(titles[i]);
            tel.setText(tels[i]);

            return view1;
        }
    }


}